{extend name="homeheader:header"/}
{block name="content"}
	<link rel="stylesheet" type="text/css" href="/home/css/shop.css" />
	<body style="overflow-x: hidden;">
		<div class="order">
			<div class="top">
				<a href="javascript:history.back(-1)" class="back">
					<i class="iconfont">&#xe615;</i></a>
				购物车
			</div>
			{if condition="$list neq null"}
			<ul class="shop_list">
				{volist name="list" id="vo"}
					<li>
						<div class="wrap_bt">
							<div class="b_top container row">
								<div class="le col-xs-3">
									<img src="{$vo.g_pic.url}" class="imgs"/>
								</div>
								<div class="col-xs-9">
									<h3>{$vo.g_name}</h3>
									<small>{$vo.g_description}</small>
								</div>
							</div>
							<div class="b_se">
								<p>购买数量</p>
								<ul class="name row">
									<li>规格</li>
									<li>单价</li>
									<li>购买数量</li>
									<li>总价</li>
								</ul>
								<ul class="init row">
									{foreach name="vo['info']" item="v2"}
										<input type="hidden" value="{$v2.iid}" id="goodstype{$v2.iid}">
										<li>{$v2.i_name}</li>
										<li>￥{$v2.i_price}</li>
										<li>{$v2.ci_number}</li>
										<li>￥{$v2.ci_total}</li>
									{/foreach}
								</ul>
							</div>
							<div class="mone">
								<div class="cartcheck">
									<input type="checkbox" name="like1[write]" lay-skin="primary" title="" class="son" name="checked_goods" value="{$vo.id}" id="{$vo.gid}"/>
									<span>合计</span>
									<span style="color:red;">￥</span><span class="mn" id="total_price{$vo.id}">{$vo.t_total}</span>
									<a class="deletecart" id="{$vo.id}">删除</a>
									<a href="#">修改</a>
								</div>
							</div>
						</div>
					</li>
				{/volist}
			</ul>
			<div class="footer">
				<div class="cartcheck">
					<input type="checkbox" name="like1[write]" lay-skin="primary" title="" id="allcheck" />
					<span>全选</span>
				</div>
				<div class="right">
					<span>合计</span>
					<span style="color:red;">￥</span><span id="totals" style="color:red;">0</span>
					<a id="settlement">结算</a>
				</div>
			</div>
			{else/}
	            <li style="text-align: center;margin-top: 50%;"><a href="{:url('/home/index/index')}">去购物</a></li>
	        {/if}
		</div>
	</body>
	<script type="text/javascript">
		layui.use(['form', 'layedit', 'laydate'], function() {
			var form = layui.form,
				layer = layui.layer,
				layedit = layui.layedit,
				laydate = layui.laydate;
		})
	</script>
	<script type="text/javascript">
		$(document).ready(function () {

		    getAllPrice();

		    /* 全选 */
		    $("#allcheck").click(function () {

		        if(this.checked ==  true){
		            $('[type=checkbox]').prop('checked', true);
		        }else{
		            $('[type=checkbox]').prop('checked', false);
		        }
		        getAllPrice();
		    });

		    /* 单选 */
		    $(".son").click(function () {
		        //总的checkbox的个数
		        var len =   $(".son").length;
		        //已选中的checkbox的个数
		        var checkedLen  =   $("input[type='checkbox'][name='checked_goods']:checked").length;
		        if(len  ==  checkedLen){
		            $('#allcheck').prop('checked', true);
		        }else{
		            $('#allcheck').prop('checked', false);
		        }
		        getAllPrice()
		    });

		});

		/* 总金额 */
		function getAllPrice() {

		    var s =  0;

		    $(".son").each(function () {

		        if(this.checked == true){
		            var id  = $(this).val();

		            s += parseInt($("#total_price"+id).text());
		        }
		    });

		    $("#totals").text(s);
		}

		/* 选择购物车里的商品 */
		$('#settlement').click(function(){
			var o_tprice = $('#totals').text();
			/* 把购物车的id存到arr数组中 */
			var arr=[];
			var gids = [];
	  	  	$("input[type='checkbox'][class='son']:checked").each(function(){ 
	  	  		arr.push($(this).val());
	  	  		gids.push($(this).attr('id'));

	  	  	});
	  	  	
			if(arr.length == 0){
				layer.msg('你还没有选择商品', {icon: 5});
				return false;
			}else{
                window.location.href="/home/Orders/corder/?ids="+arr+"&total="+o_tprice+"&gids="+gids;
			}
		});

		/* 删除购物车 */
		$('.deletecart').click(function(){
			var tid = $(this).attr('id');
			$.post('/home/carts/deleteCart',{id:tid},function(res){

				if(res.code == 0){
					layer.msg('删除成功', {icon:6});
					setTimeout(function(){
    					window.location="/home/carts/carts";
    				},1000);
				}
			},'json');
		});
	</script>
</html>
{/block}